<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
	<button>post</button>
	<button>get</button>
	<button>put</button>
	<button>patch</button>
	<button>delete</button>
</body>
<script>
	const btns = document.querySelectorAll("button");
	btns[0].onclick = function(){
		// application/json
		// const xhr = new XMLHttpRequest();
		// xhr.responseType = "json";
		// xhr.open("post","http://zhangpeiyue.com/scoreList");
		// xhr.setRequestHeader("Content-Type","application/json")
		// xhr.send(JSON.stringify({
		// 	userName:"古力娜扎",
		// 	age:20
		// }));
		// xhr.onload = function(){
		// 	console.log(xhr.response);
		// }
		
		const xhr = new XMLHttpRequest();
		xhr.responseType = "json";
		xhr.open("post","http://zhangpeiyue.com/scoreList");
		xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
		xhr.send("a=1&b=2");
		xhr.onload = function(){
			console.log(xhr.response);
		}
	}
	btns[1].onclick = function(){
		const xhr = new XMLHttpRequest();
		xhr.responseType = "json";
		xhr.open("get","http://zhangpeiyue.com/scoreList/4");
		xhr.send();
		xhr.onload = function(){
			console.log(xhr.response);
		}
	}
	btns[2].onclick = function(){
		// const xhr = new XMLHttpRequest();
		// xhr.responseType = "json";
		// xhr.open("put","http://zhangpeiyue.com/scoreList/4");
		// xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
		// xhr.send("a=1&b=2");
		// xhr.onload = function(){
		// 	console.log(xhr.response);
		// }
		
		const xhr = new XMLHttpRequest();
		xhr.responseType = "json";
		xhr.open("put","http://zhangpeiyue.com/scoreList/4");
		xhr.setRequestHeader("Content-Type","application/json")
		xhr.send(JSON.stringify({
			a:100,
			b:200
		}));
		xhr.onload = function(){
			console.log(xhr.response);
		}
	}
	btns[3].onclick = function(){
		const xhr = new XMLHttpRequest();
		xhr.responseType = "json";
		xhr.open("PATCH","http://zhangpeiyue.com/scoreList/5");
		xhr.setRequestHeader("Content-Type","application/json")
		xhr.send(JSON.stringify({
			userName:"zhangsan"
		}));
		xhr.onload = function(){
			console.log(xhr.response);
		}
	}
	btns[4].onclick = function(){
		const xhr = new XMLHttpRequest();
		xhr.responseType = "json";
		xhr.open("delete","http://zhangpeiyue.com/scoreList/5");
		xhr.send();
		xhr.onload = function(){
			console.log(xhr.response);
		}
	}
	
</script>
</html>